//////////////////////////////////////////////////////////////////////////
//
// Application entry-point
// 
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <windowsx.h>

// Media Foundation 
#include <mfapi.h>
#include <mfidl.h>
#include <mfreadwrite.h>
#include <mferror.h>

// Shell
#include <shobjidl.h>
#include <shellapi.h> 

// Direct2D
#include <D3d9.h>
#include <Dxva2api.h>

// Misc
#include <strsafe.h>
#include <assert.h>
#include <propvarutil.h>

#include "CAudioPlayer.h"


// Include the v6 common controls in the manifest
#pragma comment(linker, \
    "\"/manifestdependency:type='Win32' "\
    "name='Microsoft.Windows.Common-Controls' "\
    "version='6.0.0.0' "\
    "processorArchitecture='*' "\
    "publicKeyToken='6595b64144ccf1df' "\
    "language='*'\"")


IMFSourceReader *m_pReader;

BOOL InitializeApp()
{
	HRESULT hr = S_OK;

	// Initialize COM
	hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

	if (SUCCEEDED(hr))
	{
		// Initialize Media Foundation.
		hr = MFStartup(MF_VERSION);
	}

	return (SUCCEEDED(hr));
}

void CleanUp()
{
	MFShutdown();
	CoUninitialize();
}

int main(int, char**)
{
	InitializeApp();

	CAudioPlayer *audioPlayer = new CAudioPlayer();
	audioPlayer->Prepare(L"d:\\test-file\\test.mp4", GetConsoleWindow());
	audioPlayer->Play();
	Sleep(3000);
	audioPlayer->Pause();
	Sleep(3000);
	audioPlayer->Play();
	Sleep(3000);
	audioPlayer->Stop();
	Sleep(3000);
	audioPlayer->Play();
	while (audioPlayer->GetStatus() != CAudioPlayer::Stopped) {
		Sleep(300);
	}
	delete audioPlayer;

    CleanUp();

    return 0;
}

